<?php  
session_start();  
include 'configs/config.php';  

$message = "";  

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['article_id'])) {  
    if (isset($_SESSION['user_id'])) {  
        $article_id = $_POST['article_id'];  

        $stmt = $conn->prepare("DELETE FROM article WHERE id = ? AND user_id = ?");  
        $stmt->bind_param("ii", $article_id, $_SESSION['user_id']);  

        if ($stmt->execute()) {  
            $message = "文章删除成功！";  
        } else {  
            $message = "删除失败: " . $stmt->error;  
        }  
        $stmt->close();  
    } else {  
        $message = "请先登录！";  
    }  
}  

header("Location: view_articles.php?message=" . urlencode($message));  
exit();  
?>